package com.me.myapplication;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.PathEffect;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatTextView;

public class LinedWriteTextView extends AppCompatTextView {


    Paint mPaint;

    public LinedWriteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    private void initPaint() {
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.LTGRAY);
        PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},5);
        mPaint.setPathEffect(effects);
    }


    @Override protected void onDraw(Canvas canvas) {

        int left = getLeft();
        int right = getRight();
        int paddingTop = getPaddingTop();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int lineHeight = getLineHeight();
        int spacingHeight = (int) getLineSpacingExtra();
        int count = 5000; //(height-paddingTop-paddingBottom) / lineHeight;


        for (int i = 0; i < count; i++) {
            int baseline = lineHeight * (i+1) + paddingTop - spacingHeight/3;
            canvas.drawLine(left-paddingLeft, baseline, right-paddingRight, baseline, mPaint);
        }

        super.onDraw(canvas);
    }
}

